<?php

/***  DOCUMENTATION LAYER

Last Update: Mar 2007
	
DESCRIPTION
	this function will split an array into an array of the given number of columns
	
NOTES
	
***/

// Timer
$_tx0 = microtime();

// HEADER
echo "<h1 style='margin:8px 0 0;'>PHP Sandbox</h1>";
echo "<h4 style='margin:0 0 16px;'>array_to_cols()</h4>";	// put script name here

// *** PROCEDURAL
if ( 0 ) 
{
	echo "<h4 style='margin:0; color:blue;'>Testing in Progess</h4>";
}


$_DIR['php'] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
require_once($_DIR['php'] . 'array/array_to_cols.inc.php');


// Test Function
if ( 1 )
{
	$run = 3;
	echo "<h2 style='margin:0; color:green;'>Function Test</h2>";	
	while ( $run )
	{
		if ( $run % 2 == 0 )
		{ 
			$ARRAY = array();
			for ( $i = 0; $i < mt_rand(20,40); $i++ ) { $ARRAY[substr(md5($i),-3)] = md5(mt_rand(1,1000)); }
		}
		else
		{
			$z = 0;
			$ARRAY = array();
			for ( $i = 0; $i < mt_rand(10,20); $i++ ) 
			{
				$SUBARRAY = array();
				for ( $j = 0; $j < mt_rand(1,3); $j++ ) 
				{
					$z++; 
					$SUBARRAY[substr(md5($z),-3)] = md5(mt_rand(1,1000)); 
				} 
				$ARRAY[substr(md5($i),-3)] = $SUBARRAY; 
			}
		}
		
		$array_cnt = count($ARRAY);
		$array0 = print_r($ARRAY,1);
		echo "<p>ARRAY start ($array_cnt elements)</p><pre style='border:1px solid #ccc; background:#eee;'>$array0</pre>";
		
		$num_cols = mt_rand(2,5);
		$ARRAY_COL = array_to_cols($ARRAY, $num_cols);
		$arrayn = print_r($ARRAY_COL,1);
		echo "<p>ARRAY end ($num_cols cols)</p><pre style='border:1px solid #ccc; background:#efe;'>$arrayn</pre>";
		
		echo "<h6 style='margin:0; color:#ccc;'>test #{$run} complete</h6>";
		$run--;
	}
}

// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
$footer = <<<HTML
<h4 style="margin:0; position:absolute; top:6px; right:6px; font-family:monospace; color:#36f; padding:4px; border:1px solid #36f; font-weight:normal; background:#f3f6ff;">
script completed in $stx s
</h4>
HTML;
echo $footer;

?>
